/*
   Copyright (c) 2023 李伟国
   learner-platform is licensed under Mulan PSL v2.
   You can use this software according to the terms and conditions of the Mulan PSL v2. 
   You may obtain a copy of Mulan PSL v2 at:
               http://license.coscl.org.cn/MulanPSL2 
   THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.  
   See the Mulan PSL v2 for more details. 
*/

package cn.platform.service.impl;

import cn.platform.constant.enumeration.StatusConstantEnum;
import cn.platform.entity.Label;
import cn.platform.mapper.LabelMapper;
import cn.platform.page.PageFactory;
import cn.platform.service.ILabelService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LabelServiceImpl extends ServiceImpl<LabelMapper, Label> implements ILabelService {

    /**
     * 得到可用的标签列表
     *
     * @return 标签列表
     */
    @Override
    public List<Label> findLabelMenuList() {
        return this.baseMapper.selectMenuList();
    }

    /**
     * 保存标签
     *
     * @param label 标签
     * @return 是否成功保存
     */
    @Override
    public Boolean saveLabel(Label label) {
        label.setStatus(StatusConstantEnum.ENABLE.getCode());
        return this.baseMapper.insert(label) > 0;
    }

    /**
     * 获得所有标签列表
     *
     * @return 标签列表
     */
    @Override
    public Page<Label> findAll() {
        return this.baseMapper.selectAll(PageFactory.defaultPage());
    }

    /**
     * 删除标签
     *
     * @param label
     */
    @Override
    public Boolean deleteLabel(Label label) {
        return this.baseMapper.updateStatusById(label.getId(),StatusConstantEnum.DELETED.getCode());
    }

    /**
     * 恢复删除
     *
     * @param label
     */
    @Override
    public Boolean resetLabel(Label label) {
        return this.baseMapper.updateStatusById(label.getId(), StatusConstantEnum.ENABLE.getCode());
    }

}
